﻿using Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using Web.Class;
using Platform.Common;


namespace Web.Controls.LAIHAN
{
    public partial class UCLHJiHuaZYUserInfo : System.Web.UI.UserControl
    {
        #region 属性
        private string _JY;
        /// <summary>
        /// 转出用户还是转入用户
        /// </summary>
        public string JY
        {
            get { return _JY; }
            set { _JY = value; }
        }
        public string XuKeBM
        {
            get { return txtXuKeSLBH.Text; }
        }
        public string TONGYIBM
        {
            get { return txtTongYiSPBH.Text; }
        }

        public string ZhanDianBH
        {
            get { return UCLHJiHuaZYUserInfo_HiddenList.Contains("ZhanDian")?UCLHJiHuaZYUserInfo_HiddenList.Get("ZhanDian").ToString():""; }
        
        }
        public string GuanLiKJ
        {
            get { return UCLHJiHuaZYUserInfo_HiddenList.Contains("GLKJ")?UCLHJiHuaZYUserInfo_HiddenList.Get("GLKJ").ToString():""; }
        }
        public int Y
        {
            get { return Convert.ToInt32(txtShuiLiangN.Text==""?"0":txtShuiLiangN.Text); }
            set { txtShuiLiangN.Text = value.ToString(); }
        }
        public string TxtYongHuH
        {
            get { return txtZhuanChuYHHJ.Text; }
            set { txtZhuanChuYHHJ.Text = value; }
        }
        /// <summary>
        /// 转出用户名
        /// </summary>
        public string ZhuanChuYHMJ
        {
            get { return txtZhuanChuYHMJ.Text; }
            set { txtZhuanChuYHMJ.Text = value; }
        }
        /// <summary>
        /// 转入用户名
        /// </summary>
        public string ZhuanRuYHMY
        {
            get { return txtZhuanRuYHMY.Text; }
            set { txtZhuanRuYHMY.Text = value; }
        }
        /// <summary>
        /// 转出地址
        /// </summary>
        public string ZhuanChuDZJ
        {
            get { return txtZhuanChuDZJ.Text; }
            set { txtZhuanChuDZJ.Text = value; }
        }
        /// <summary>
        /// 转入地址
        /// </summary>
        public string ZhuanRuDZY
        {
            get { return txtZhuanRuDZY.Text; }
            set { txtZhuanRuDZY.Text = value; }
        }
        /// <summary>
        /// 转出联系人
        /// </summary>
        public string ZhuanChuLXRJ
        {
            get { return txtZhuanChuLXRJ.Text; }
            set { txtZhuanChuLXRJ.Text = value; }
        }
        /// <summary>
        /// 转入联系人
        /// </summary>
        public string ZhuanRuLXRY
        {
            get { return txtZhuanRuLXRY.Text; }
            set { txtZhuanRuLXRY.Text = value; }
        }
        /// <summary>
        /// 转出联系电话
        /// </summary>
        public string ZhuanChuLXDHJ
        {
            get { return txtZhuanChuLXDHJ.Text; }
            set { txtZhuanChuLXDHJ.Text = value; }
        }
        /// <summary>
        /// 转入联系电话
        /// </summary>
        public string ZhuanRuLXDHY
        {
            get { return txtZhuanRuLXDHY.Text; }
            set { txtZhuanRuLXDHY.Text = value; }
        }

        private string _YongHuHJ;
        /// <summary>
        /// 用户号 甲
        /// </summary>
        public string YongHuHJ
        {
            get { return UCLHJiHuaZYUserInfo_HiddenList.Contains("YongHuHJ")?UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHJ").ToString():""; }
            set { UCLHJiHuaZYUserInfo_HiddenList.Set("YongHuHJ", value); }
        }
       
        
        public bool YongHuHYEnabled
        {
            get { return this.txtZhuanRuYHHY.Enabled; }
            set { this.txtZhuanRuYHHY.Enabled = value; }
        }
        private string _YongHuHY;
        /// <summary>
        /// 用户号 乙
        /// </summary>
        public string YongHuHY
        {
            get { return UCLHJiHuaZYUserInfo_HiddenList.Contains("YongHuHY")?UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHY").ToString():""; }
            set { UCLHJiHuaZYUserInfo_HiddenList.Set("YongHuHY", value); }
        }

        /// <summary>
        /// 来函编号
        /// </summary>
        private string _LaiHanBH;

        public string LaiHanBH
        {
            get { return _LaiHanBH; }
            set { _LaiHanBH = value; }
        }

        private bool _SumbitYN;
        /// <summary>
        /// 计划信息是否符合绑定完整
        /// </summary>
        public bool SumbitYN
        {
            get { return _SumbitYN; }
            set { _SumbitYN = value; }
        }
        
        #endregion

        #region 变量
        /// <summary>
        /// 用户信息bll
        /// </summary>
        YS_YG_YONGHUXXBLL YongHuBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// 访问数据库存储过程
        /// </summary>
        SpHelper _sphelper = new SpHelper();

        /// <summary>
        /// 来函用户信息
        /// </summary>
        YS_LH_YONGHUXXProcess lhyonghuxx = new YS_LH_YONGHUXXProcess();

        #endregion

        #region 事件
        /// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }
        /// <summary>
        /// 绑定用户甲
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Btn_Click(object sender, EventArgs e)
        {
            BindUser(1);
          
        }
        /// <summary>
        /// 绑定用户乙
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnY_Click(object sender, EventArgs e)
        {
            
            BindUser(2);
        }
        /// <summary>
        /// 清空用户信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnClear_Click(object sender, EventArgs e)
        {
            int type = 0;
            if (UCLHJiHuaZYUserInfo_HiddenList.Get("JY").ToString() == "J")
            {
                ClearUserInfo(1);
            }
            else
            {
                ClearUserInfo(2);
            }
        }
        /// <summary>
        /// callback事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void UCLHJiHuaZYUserInfo_CallBackSelect(object source, DevExpress.Web.CallbackEventArgs e)
        {
            e.Result = e.Parameter;
            if (e.Parameter == "yonghuhj")
            {

                e.Result = e.Parameter+"|"+CheckUserSelect(e.Parameter,UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHJ").ToString().Trim());
            }
            if (e.Parameter == "yonghuhy")
            {

                e.Result = e.Parameter + "|" + CheckUserSelect(e.Parameter, UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHY").ToString().Trim());
            }

        }
        #endregion

        #region 方法
        /// <summary>
        /// 绑定材料信息
        /// </summary>
        /// <param name="uc"></param>
        public void CheckCaiLiao(UCLHCaiLiaoInfo uc)
        {
            uc.BindCheckBox(this.YongHuHJ,"");
        }
        /// <summary>
        /// 验证计划转移信息
        /// </summary>
        /// <returns></returns>
        public string CheckJHXX()
        {
            string retstr = "";
            if (H_YongHUHJ.Value.Trim().Length == 0 || H_YongHUHY.Value.Trim().Length == 0)
            {
                retstr = "-1|请先查询相关用户信息";
            }
            else
            {
                retstr = "1|验证通过";
            }
            return retstr;
        }
        /// <summary>
        /// 获得原计划信息
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public DataSet BindJHXX(int type)
        {
            this.JY = "转出用户";
            DataSet ds = null;
            int y = 0;
            if (int.TryParse(txtShuiLiangN.Text.Trim(),out y))
            {
                if (type == 1)
                {
                    ds = _sphelper.P_YS_LH_YSJHTIAOZHENGJHCX(BusinessTool.ZHANDIANBH(), UCLHJiHuaZYUserInfo_HiddenList.Get("GLKJ").ToString().Trim(), UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHJ").ToString().Trim(), Convert.ToInt32(txtShuiLiangN.Text));

                }
                else
                {
                    ds = _sphelper.P_YS_LH_YSJHTIAOZHENGJHCX(BusinessTool.ZHANDIANBH(), UCLHJiHuaZYUserInfo_HiddenList.Get("GLKY").ToString().Trim(), UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHY").ToString().Trim(), Convert.ToInt32(txtShuiLiangN.Text));

                }
            }
            return ds;
        }
        /// <summary>
        /// 验证用户信息
        /// </summary>
        /// <param name="key"></param>
        /// <param name="yonghubh"></param>
        /// <returns></returns>
        private string CheckUserSelect(string key,string yonghubh)
        {
            string retstring = "";
            DataTable YongHuXX = YongHuBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format(" S_YONGHUH='{0}' and I_leixing=0 and i_JLZT=0", yonghubh), "", null);

            if (LaiHanLCTools.HasRelationExists((int)eLaiHanLX.计划转移, null, yonghubh, txtShuiLiangN.Text, null, out retstring))
            {
                return "-3|"+retstring;
            }
            if (YongHuXX != null && YongHuXX.Rows.Count > 0)
            {
                retstring = "1|验证通过|" + YongHuXX.Rows[0]["S_YONGHUH"] + "|" + YongHuXX.Rows[0]["S_YONGHUM"] + "|" + YongHuXX.Rows[0]["S_DIZHI"] + "|" + YongHuXX.Rows[0]["S_LianXIR"] + "|" + YongHuXX.Rows[0]["S_LianXIDH"] + "|" + YongHuXX.Rows[0]["S_GuanLikBH"] + "|" + YongHuXX.Rows[0]["S_ZhanDianBH"];
                
                if (UCLHJiHuaZYUserInfo_HiddenList.Contains("YongHuHJ") && UCLHJiHuaZYUserInfo_HiddenList.Contains("YongHuHY"))
                { 
                    string j= UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHJ").ToString().Trim();
                    string y= UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHY").ToString().Trim();
                    if(j==y)
                    {
                        retstring = "-2|转入转出用户为同一人";
                        return retstring;
                    }
                }

            }
            else
            {
                retstring = "-1|查询不到该用户信息";
                return retstring;

            }

            return retstring;
        }
        /// <summary>
        /// 查询用户信息
        /// </summary>
        /// <param name="type">1甲  2乙</param>
        private void BindUser(int type)
        {
            string yonghubh = "";
            if (type == 2)
            {
                yonghubh = UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHY").ToString().Trim();
            }
            else
            {
                yonghubh = UCLHJiHuaZYUserInfo_HiddenList.Get("YongHuHJ").ToString().Trim();
            }
            if (yonghubh.Length == 0)
            {
                return;
            }
            string zhandian = BusinessTool.ZHANDIANBH() == "00" ? "" : " and S_ZHANDIANBH='" + BusinessTool.ZHANDIANBH() + "'";
            DataTable YongHuXX = YongHuBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format(" S_YONGHUH='{0}' and I_leixing=0 and i_JLZT=0 "+zhandian, yonghubh), "", null);
            if (YongHuXX != null && YongHuXX.Rows.Count > 0)
            {
                DataRow dr = YongHuXX.Rows[0];
                if (type == 1)
                {
                    txtZhuanChuYHMJ.Text = dr["S_YONGHUM"].ToString();
                    txtZhuanChuDZJ.Text = dr["S_DIZHI"].ToString();
                    txtZhuanChuLXRJ.Text = dr["S_LianXIR"].ToString();
                    txtZhuanChuLXDHJ.Text = dr["S_LianXIDH"].ToString();
                    H_YongHUHJ.Value = dr["S_YONGHUH"].ToString();
                    H_GuanLiKJ.Value = dr["S_GuanlikBH"].ToString();

                    this.YongHuHJ = dr["S_YONGHUH"].ToString();

                  
                }
                else
                {
                    txtZhuanRuYHMY.Text = dr["S_YONGHUM"].ToString();
                    txtZhuanRuDZY.Text = dr["S_DIZHI"].ToString();
                    txtZhuanRuLXRY.Text = dr["S_LianXIR"].ToString();
                    txtZhuanRuLXDHY.Text = dr["S_LianXIDH"].ToString();
                    H_YongHUHY.Value = dr["S_YONGHUH"].ToString();
                    H_GuanLiKY.Value = dr["S_GuanlikBH"].ToString();
                    this.YongHuHY = dr["S_YONGHUH"].ToString();
                }

            }
        }
        /// <summary>
        /// 清空用户信息
        /// </summary>
        /// <param name="type"></param>
        private void ClearUserInfo(int type)
        {
            if (type == 1)
            {
                txtZhuanChuYHMJ.Text = "";
                txtZhuanChuDZJ.Text = "";
                txtZhuanChuLXRJ.Text = "";
                txtZhuanChuLXDHJ.Text = "";
                H_YongHUHJ.Value = "";
                H_GuanLiKJ.Value = "";
            }
            else
            {
                txtZhuanRuYHMY.Text = "";
                txtZhuanRuDZY.Text = "";
                txtZhuanRuLXRY.Text = "";
                txtZhuanRuLXDHY.Text ="";
                H_YongHUHY.Value = "";
                H_GuanLiKY.Value = "";
            }
        }
        /// <summary>
        /// 根据来函信息加载用户信息/计划信息
        /// </summary>
        /// <param name="jyonghu"></param>
        /// <param name="yyonghu"></param>
        /// <param name="laihan"></param>
        public void LoadInfo(string jyonghu,string yyonghu,YS_LH_LAIHANXX laihan)
        {
            txtZhuanChuYHHJ.Text = jyonghu;
            txtZhuanRuYHHY.Text = yyonghu;

            PageTools.SetDisabled(txtZhuanRuYHHY,true);
            PageTools.SetDisabled(txtZhuanChuYHHJ, true);
            PageTools.SetDisabled(txtShuiLiangN, true);
           

            txtLaiHanBH.Text = laihan.S_LAIHANBH;
            txtShuiLiangN.Text = laihan.I_Y.ToString();
            txtTongYiSPBH.Text = laihan.S_TONGYIBM;
            txtXuKeSLBH.Text = laihan.S_XUKEBH;
            UCLHJiHuaZYUserInfo_HiddenList.Set("ZhanDian", laihan.S_ZHANDIANBH);
            UCLHJiHuaZYUserInfo_HiddenList.Set("GLKJ", laihan.S_GUANLIKBH);
            UCLHJiHuaZYUserInfo_HiddenList.Set("GLKY", laihan.S_GUANLIKBH);

            DataTable glktable = YongHuBLL.SelectYS_YG_YONGHUXXesDynamic(" S_YONGHUH='" + jyonghu + "'", "", null);
            if (null != glktable&&glktable.Rows.Count>0)
            {
                UCLHJiHuaZYUserInfo_HiddenList.Set("GLKJ", glktable.Rows[0]["S_GUANLIKBH"]);
            }
            glktable = YongHuBLL.SelectYS_YG_YONGHUXXesDynamic(" S_YONGHUH='" + yyonghu + "'", "", null);
            if (null != glktable && glktable.Rows.Count > 0)
            {
                
                UCLHJiHuaZYUserInfo_HiddenList.Set("GLKY", glktable.Rows[0]["S_GUANLIKBH"]);
            }

            string JiaWhere = string.Format(" S_YONGHUBH='{0}' and S_LAIHANBH='{1}' ",jyonghu,laihan.S_LAIHANBH);
            DataTable JiaYongh = lhyonghuxx.SelectYS_LH_YONGHUXXesDynamic(JiaWhere,"",null);

            if (JiaYongh != null && JiaYongh.Rows.Count > 0)
            {
                DataRow dr = JiaYongh.Rows[0]; 
                txtZhuanChuYHMJ.Text = dr["S_YONGHUM"].ToString();
                txtZhuanChuDZJ.Text = dr["S_DIZHI"].ToString();
                txtZhuanChuLXRJ.Text = dr["S_LianXIR"].ToString();
                txtZhuanChuLXDHJ.Text = dr["S_LianXIDH"].ToString();              

                UCLHJiHuaZYUserInfo_HiddenList.Set("YongHuHJ", dr["S_YONGHUBH"].ToString());
            }

            string YiWhere = string.Format(" S_YONGHUBH='{0}' and S_LAIHANBH='{1}' ", yyonghu, laihan.S_LAIHANBH);
            DataTable YiYongh = lhyonghuxx.SelectYS_LH_YONGHUXXesDynamic(YiWhere, "", null);
            if (YiYongh != null && YiYongh.Rows.Count > 0)
            {
                DataRow dr = YiYongh.Rows[0];

                txtZhuanRuYHMY.Text = dr["S_YONGHUM"].ToString();
                txtZhuanRuDZY.Text = dr["S_DIZHI"].ToString();
                txtZhuanRuLXRY.Text = dr["S_LianXIR"].ToString();
                txtZhuanRuLXDHY.Text = dr["S_LianXIDH"].ToString();
               
              
                UCLHJiHuaZYUserInfo_HiddenList.Set("YongHuHY", dr["S_YONGHUBH"].ToString());
            }
            if (laihan.I_LIUCHENGBH > 0)
            {
                SetShouLiStatus();
            }
        }
        public void SetShouLiStatus()
        {
            txtZhuanRuYHMY.ReadOnly = true;
            txtZhuanRuDZY.ReadOnly = true;
            txtZhuanRuLXRY.ReadOnly = true;
            txtZhuanRuLXDHY.ReadOnly = true;

            txtZhuanChuYHMJ.ReadOnly = true;
            txtZhuanChuDZJ.ReadOnly = true;
            txtZhuanChuLXRJ.ReadOnly = true;
            txtZhuanChuLXDHJ.ReadOnly = true;
        }
       public void YongHuHJFocus()
        {
            this.txtZhuanChuYHHJ.Focus();
        }
       public void YongHuHYFocus()
       {
           this.txtZhuanRuYHHY.Focus();
       }
       public void YMFocus()
       {
           this.txtShuiLiangN.Focus();
       }
        #endregion
    }
}